package edu.ou.herbarium.threads2;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;

import edu.ou.herbarium.sharedata.ShareData7;
import edu.ou.herbarium.sharedata.ShareData8;
import edu.ou.herbarium.sharedata.TransferData7;
import edu.ou.herbarium.sharedata.TransferData8;
import edu.ou.herbarium.threads.TransferData;
import edu.ou.herbarium.wsclient.DataUtilsDelegate;
import edu.ou.herbarium.wsclient.DataUtilsService;
import edu.ou.herbarium.wsclient.Specimen;

public class RemoteThread extends Thread{
	ShareData7 s7;
	ShareData8 s8;
	
	public RemoteThread(ShareData7 s7, ShareData8 s8){
		this.s7 = s7;
		this.s8 = s8;
	}
	
	public void run(){
		while (true) {
			TransferData7 d7 = s7.getShareData();
			Specimen spec = d7.getSpec();
			String split [] = d7.getOriginalFilePath().split("/");
			String sub1 = split[split.length-1];
			String sub2 = split[split.length-2];
			DataUtilsService service = new DataUtilsService();
			DataUtilsDelegate delegate = service.getDataUtilsPort();
			try{
				Specimen name = delegate.insertSpecimen(sub2+"_"+sub1, d7.getSpec().getTempData()
					, d7.getSpec(), d7.getByte1(), d7.getByte2(), d7.getByte3(), d7.getByte4());
				TransferData8 d8 = new TransferData8(name,d7.getByte4(),d7.getOriginalFilePath(),sub2);
				s8.setShareData(d8);
			}catch(Exception e){
				e.printStackTrace();
			}
			

		}
	}
}
